package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.CommonPlaceDto;
import com.enjoyor.soa.traffic.api.dto.tsms.PoliceCallNameDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ICommonPlaceConsumeService;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IPoliceCallNameConsumeService;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/policeCallName" })
@Api("PoliceCallNameContreoller相关api")
@CrossOrigin
public class PoliceCallNameContreoller {
	
	@Autowired
	private IPoliceCallNameConsumeService iPoliceCallNameConsumeService;
	
	/**
	 * 点名信息分页
	 * @param page 分页参数
	 * @return zyh
	 */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getPoliceCallNamePage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("点名信息分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "callId", value = "点名编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string")})
    public ResultPojo getCommonPlacePage(@RequestParam(defaultValue = "")String postId, 
			@RequestParam(defaultValue = "") String policeId,
			@RequestParam(defaultValue = "") String callId, 
			@RequestParam(defaultValue = "") String executeTaskId, 
    		Page page, HttpServletRequest request){
    	
    	ResultPojo resultPojo = new ResultPojo();
    	resultPojo = iPoliceCallNameConsumeService.getPoliceCallNamePage(page, postId, policeId, callId, executeTaskId);
    	return resultPojo;
    }
    
    /**
	 * 点名信息 List；
	 * @return zyh
	 */
	@GetMapping(value = { "/getPoliceCallNameList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=PoliceCallNameDto.class, code = 0, message = "")
    @ApiOperation("点名信息list查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "callId", value = "点名编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string")})
	public ResultPojo getCommonPlaceList(@RequestParam(defaultValue = "")String postId, 
			@RequestParam(defaultValue = "") String policeId,
			@RequestParam(defaultValue = "") String callId, 
			@RequestParam(defaultValue = "") String executeTaskId, 
    		HttpServletRequest request) {
		return iPoliceCallNameConsumeService.getPoliceCallNameList(postId, policeId, callId, executeTaskId);
	}
	
	/**
	 * 点名信息添加
	 * @param commonPlaceDto
	 * @param request
	 * @returnzyh
	 */
	@PutMapping(value = { "/addPoliceCallStatus" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("警员点名(到岗、离岗)")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "policeName", value = "警员名称", paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "isPosting", value = "是否在岗(到岗：1、离岗：0)", paramType = "query", dataType = "String")})
	public ResultPojo addPoliceCallStatus(
			@RequestParam(defaultValue = "",value="executeTaskId",required=true)String executeTaskId, 
			@RequestParam(defaultValue = "",value="postId",required=false) String postId,
			@RequestParam(defaultValue = "",value="policeId",required=true) String policeId, 
			@RequestParam(defaultValue = "",value="policeName",required=true) String policeName, 
			@RequestParam(defaultValue = "",value="isPosting",required=true) String isPosting, 
			HttpServletRequest request) {
		PoliceCallNameDto policeCallNameDto = new PoliceCallNameDto();
		policeCallNameDto.setExecuteTaskId(executeTaskId);
		policeCallNameDto.setPoliceId(policeId);
		policeCallNameDto.setPoliceId(policeId);
		policeCallNameDto.setPoliceName(policeName);
		if("1".equals(isPosting)) {
			policeCallNameDto.setCallStatusId("POLICESTATUS01");
			policeCallNameDto.setCallStatusName("到岗");
		}else if("0".equals(isPosting)) {
			policeCallNameDto.setCallStatusId("POLICESTATUS02");
			policeCallNameDto.setCallStatusName("离岗");
		}else {
			return new ResultPojo(EnumAppCode.PARAM_ERR, "参数错误(是否在岗(到岗：1、离岗：0))");
		}
		return iPoliceCallNameConsumeService.insertPoliceCallName(policeCallNameDto,
					((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 点名信息添加
	 * @param commonPlaceDto
	 * @param request
	 * @returnzyh
	 */
	@PostMapping(value = { "/addPoliceCallName" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加点名信息")
	public ResultPojo addCommonPlace(@RequestBody PoliceCallNameDto policeCallNameDto, HttpServletRequest request) {
			return iPoliceCallNameConsumeService.insertPoliceCallName(policeCallNameDto,
					((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 单条点名信息修改
	 * @param commonPlaceDto
	 * @param request
	 * @return
	 */
	@PutMapping(value = { "/editPoliceCallName" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改点名信息")
	public ResultPojo editCommonPlace(@RequestBody PoliceCallNameDto policeCallNameDto, HttpServletRequest request) {
			return iPoliceCallNameConsumeService.updatePoliceCallName(policeCallNameDto,
					((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除点名信息（单条移除）
	 * @param callId
	 * @param request
	 * @return
	 */
	@DeleteMapping(value = { "/delPoliceCallName" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除点名信息")
    @ApiImplicitParam(name = "callId", value = "点名编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo delCommonPlace( 
    		@RequestParam(defaultValue = "",value="callId", required=true) String callId,
    		HttpServletRequest request) {
        return iPoliceCallNameConsumeService.deletePoliceCallName(callId, 
        		((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	

}
